﻿#ifndef MIXDEVICE_H
#define MIXDEVICE_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QMap>
#include <QTimer>
#include <QDateTime>
#include <QList>

#include "../commons/comalgor.h"

/*
 * 用于处理继电器
*/
class MixDevice : public QObject
{
    Q_OBJECT
public:
    explicit MixDevice(QObject *parent = nullptr);
    virtual ~MixDevice();
    static MixDevice * gestance();


    void initComSeriel();

    void openLanes(int start , int nums);
    void closeLanes(int start , int nums);

    void handlSingLanes(int start , int nums);

    void openPins(int pins ,int times);

    void handlCmdPins(QByteArray infors);
    void openCmdPins(int pins );
    void closeCmdPins(int pins );

    void handlPins();

signals:
    void sigMixDeviceSuccess();

public slots:
    void onDataReceived();
    void onSendTimeOut();

    void onTimeOut();

    void onCloseTimeOut();

    void onRunTimeOut();

private:

    static MixDevice * m_mixDevice;
    QSerialPort * m_serial;

    ComAlgor * m_comAlgor;
     QByteArray m_currentData ;
    QMap<int ,qint64> m_runPins;
    QMap<int ,qint64>  m_sendCmd;
    QList<int> m_closeList;
    QTimer * m_timer;
    QTimer * m_sendtimer;
    QTimer * m_closetimer;

    QTimer * m_runtimer;

    QMap<int ,int>  m_cmdPins;
    QMap<int ,int>  m_pinsMap;
    int m_cmdIndexs;
    bool m_isHandlCmds;
};

#endif // MIXDEVICE_H
